import { hasOwnMetadata } from 'core-js/fn/reflect'
import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../views/login.vue'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'login',
    component: () => import('../views/login.vue')
  },
  {
    path: '/index',
    name: 'index',
    component: () => import('../views/index.vue'),
    children:[
      {
        path: '/users',
        name: 'users',
        component: () => import('../components/index/users')
      },
      {
        path: '/roles',
        name: 'roles',
        component: () => import('../components/index/roles')
      },
      {
        path: '/rights',
        name: 'rights',
        component: () => import('../components/index/rights')
      },
      {
        path: '/categories',
        name: 'categories',
        component: () => import('../components/index/categories')
      },
      {
        path: '/params',
        name: 'params',
        component: () => import('../components/index/params')
      },
      {
        path: '/goods',
        name: 'goods',
        component: () => import('../components/index/goods'),
      },
      {
        path: '/goods/add',
        name: 'add',
        component: () => import('../components/index/add')
      },
      {
        path: '/reports',
        name: 'reports',
        component: () => import('../components/index/reports')
      },
      {
        path: '/welcome',
        name: 'welcome',
        component: () => import('../components/index/welcome')
      },
    ]
  },
]

const routes =[
    //项目正式路由开始
    {
        path:'/home',
        name:'home',
        component:Home,
        redirect:'/users',
        children:[
    // 写死的路由表。一般叫做静态路由，还可以通过js生成
    {path:''}   
        ]
    }
]
const router = new VueRouter({
  
  routes
})
// 白名单-意思是不需要token,就可以直接进入的页面
// const whiteList = ['/login']

// 路由拦截-1.先判断有没有登陆过 本地里会有token值 如果登录放行
//  router.beforeEach((to,form,next)=>{
//    let token = localStorage.getItem('token')
//    if(token){
//      next()
//    }else{
//      if(to.path=='/login'){
//        next()
//      }
//      else{
//        next('/login')
//      }
//    }
//  })
export default router
